package leetcode.code283.MoveZeroes;

/**
 * ˫ָ�룬��ͷ��
 *
 * @author Administrator
 *
 */
public class Solution1 implements IMoveZeroes {

	@Override
	public void moveZeroes(int[] nums) {
		int l = 0;// 0λ��
		int r = 0;
		int len = nums.length;
		while (l < len) {
			if (nums[l] != 0) {
				l++;
			} else {
				r = l;
				while (r < len && nums[r] == 0) {
					r++;
				}
				if (r < len) {
					nums[l] = nums[r];
					nums[r] = 0;
					l++;
				} else {
					break;
				}
			}

		}
	}

	public static void main(String[] args) {
		Solution1 so = new Solution1();
		so.debug(new int[] { 0, 1, 0, 3, 12 });
	}

//	����: [0,1,0,3,12]
//	���: [1,3,12,0,0]
	public void debug(int[] nums) {
		IMoveZeroes imz = new Solution1();
		imz.moveZeroes(nums);
		for (int num : nums) {
			System.out.print(num + ",");
		}
	}

}
